package com.iwm.qa.mdm.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.iwm.qa.mdm.R;

import static com.iwm.qa.mdm.view.AddEditDeviceActivity.EXTRA_DEVICE_OPER_TYPE;
import static com.iwm.qa.mdm.view.AddEditDeviceActivity.EXTRA_EDIT_DEVICE;

public class DeviceDetailAct extends AppCompatActivity {

    private TextView mDetailDeviceName;
    private TextView mDetailDescription;
    private TextView mDetailDeviceDepartment;
    private TextView mDetailDeviceBelongs;
    private TextView mDetailOsType;
    private TextView mDetailVersionType;
    private TextView mDetailDeviceResolution;
    private TextView mDetailDeviceAssertNumber;

    public static final String EXTRA_DEVICE_NAME = "DEVICE_NAME";
    public static final String EXTRA_DEVICE_ASSERT_NUM = "DEVICE_ASSERT_NUM";
    public static final String EXTRA_OS_TYPE = "OS_TYPE";
    public static final String EXTRA_VERSION_TYPE = "VERSION_TYPE";
    public static final String EXTRA_DEVICE_RESOLUTION = "DEVICE_RESOLUTION";
    public static final String EXTRA_REMARK = "REMARK";
    public static final String EXTRA_DEVICE_DEPT = "DEVICE_DEPT";
    public static final String EXTRA_DEVICE_BELONGS = "DEVICE_BELONGS";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_device_detail);
        initView();

        //新页面接收数据
        Bundle bundle = getIntent().getExtras();

        final String deviceName = bundle.getString(EXTRA_DEVICE_NAME);
        final String deviceAssetNum = bundle.getString(EXTRA_DEVICE_ASSERT_NUM);
        final String osType = bundle.getString(EXTRA_OS_TYPE);
        final String versionType = bundle.getString(EXTRA_VERSION_TYPE);
        final String deviceResolution = bundle.getString(EXTRA_DEVICE_RESOLUTION);
        final String remark = bundle.getString(EXTRA_REMARK);
        final String deviceDept = bundle.getString(EXTRA_DEVICE_DEPT);
        final String deviceBelongs = bundle.getString(EXTRA_DEVICE_BELONGS);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setImageResource(R.drawable.ic_edit);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(DeviceDetailAct.this, AddEditDeviceActivity.class);
                intent.putExtra(EXTRA_DEVICE_OPER_TYPE, EXTRA_EDIT_DEVICE);
                intent.putExtra("DEVICE_NAME", deviceName);
                intent.putExtra("DEVICE_ASSERT_NUM", deviceAssetNum);
                intent.putExtra("OS_TYPE", osType);
                intent.putExtra("VERSION_TYPE", versionType);
                intent.putExtra("DEVICE_RESOLUTION", deviceResolution);
                intent.putExtra("REMARK", remark);
                intent.putExtra("DEVICE_DEPT", deviceDept);
                intent.putExtra("DEVICE_BELONGS", deviceBelongs);
                startActivity(intent);
            }
        });

        mDetailDeviceName.setText(deviceName);
        mDetailDeviceDepartment.setText(deviceDept);
        mDetailDeviceBelongs.setText(deviceBelongs);
        mDetailDescription.setText(remark);
        mDetailOsType.setText(osType);
        mDetailVersionType.setText(versionType);
        mDetailDeviceResolution.setText(deviceResolution);
        mDetailDeviceAssertNumber.setText(deviceAssetNum);
    }

    private void initView() {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        mDetailDeviceName = (TextView) findViewById(R.id.device_detail_device_name);
        mDetailDeviceDepartment = (TextView) findViewById(R.id.device_detail_device_department);
        mDetailDeviceBelongs = (TextView) findViewById(R.id.device_detail_device_belongs);
        mDetailDescription = (TextView) findViewById(R.id.device_detail_description);
        mDetailOsType = (TextView) findViewById(R.id.device_detail_os_type);
        mDetailVersionType = (TextView) findViewById(R.id.device_detail_version_type);
        mDetailDeviceResolution = (TextView) findViewById(R.id.device_detail_device_resolution);
        mDetailDeviceAssertNumber = (TextView) findViewById(R.id.device_detail_device_assert_number);
    }


}
